﻿/*******************************************************************
 *     JameE
 *******************************************************************
  Copyright 2010 Clifford Champion and JameE contributors.
  
  This file is part of JameE.
  
  JameE is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  JameE is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with JameE.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************/
 
 
 
/// <reference path="~/Base/Classer.js" />
/// <reference path="~/Base/IncludeLoader.js" />

$include(
[
	"Engine/SceneObject.js"
],
function () {

	$class(
	"JameE.Assets.Objects.Group: Engine.SceneObject",
	{
		/////////////////////
		// FIELDS
		/////////////
		_arr_oChildren: null,
		_arr_oChildrenPositionOffsets: null,
		_bIsInScene: false,


		/////////////////////
		// CONSTRUCTORS
		/////////////
		_ctor: function () {
			var This = this;
			this._arr_oChildren = [];
			this._arr_oChildrenPositionOffsets = [];
		},


		/////////////////////
		// METHODS
		/////////////
		add: function (oSceneObject) {
			this._arr_oChildren.push(oSceneObject);
			if (this._bIsInScene) {
				this._oScene.add(oSceneObject);
			}
		},

		remove: function (oSceneObject) {
			JameE.Utils.Array.removeElement(this._arr_oChildren, oSceneObject);
			if (this._bIsInScene) {
				this._oScene.remove(oSceneObject);
			}
		},

		addedToScene: function (oScene) {
			this.base(oScene);
			this._bIsInScene = true;
			for (var i = this._arr_oChildren.length - 1; i >= 0; --i) {
				oScene.add(this._arr_oChildren[i]);
			}
		},

		removedFromScene: function (oScene) {
			this.base(oScene);
			this._bIsInScene = false;
			for (var i = this._arr_oChildren.length - 1; i >= 0; --i) {
				oScene.remove(this._arr_oChildren[i]);
			}
		}
	});

	$include_notify("Assets/Objects/Group.js");

});
